#ifndef FILE_TraceQueue_HPP
#define FILE_TraceQueue_HPP

#include <cstring>
#include <deque>

#include "Types.hpp"
#include "Trace.hpp"
#include "thread.hpp"

namespace se{
/********************************************//**
 * A message queue, designed for the log messages.
 *
 * You push some data on the queue on any thread.
 *
 * The logging thread then get this message, write
 * it, and delete it.
 *
 * There can be any number of pushing threads,
 * but only one read/pop-ing.
 *
 * This class is not intended to be used outside
 * of the trace.
 ***********************************************/
// TODO: see if a generalisation can be made to a
// message queue (once it will be implemented).
class System::Trace::TraceQueue{
	DISALLOW_COPY_AND_ASSIGN(TraceQueue);
	// Methods :
		public:
			TraceQueue();
			~TraceQueue();
			void Push(const char* text, Flags8_t flags, bool critical);
			void Push(const char* text, Flags8_t flags, Color_t col, bool critical);
			TraceOutput_t* GetFront(ThreadSignal_t& finish);
			void PopFront();
			void LockInput();
		private:
			// TODO : decide if it should be volatile.
			std::deque<TraceOutput_t> m_stringsToWrite;
			boost::mutex m_mutex;
			boost::condition_variable m_queueUpdated;
			ThreadSignal_t m_lockInput;
};
}// namespace se

#endif // FILE_TraceQueue_HPP
